package vesko1.model;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DBConnection {

	private static Connection con;
        public static final  String DBName = "mainDB";
	private static final String url = "jdbc:mysql://localhost:3306/"+DBName;
	public static final String username = "root";
	public static final String password = "1234";
	
	static {
		// Loading drivers for MySQL
		try {
			Class.forName("org.gjt.mm.mysql.Driver");
			// Realization connection with DB
			con = DriverManager.getConnection(url, username, password);
			// obtaining information on the connection
			DatabaseMetaData dma = con.getMetaData();
			System.out.println("\nConnected to" + dma.getURL());
			System.out.println("Driver" + dma.getDriverName());
			System.out.println("Version" + dma.getDriverVersion());
			System.out.println();
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
	}

	public static Connection getCon() {
		return con;
	}
}
